<?php
/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
class Controller extends CController
{
    protected $params=array();

	/**
	 * @var string the default layout for the controller view. Defaults to '//layouts/column1',
	 * meaning using a single column layout. See 'protected/views/layouts/column1.php'.
	 */
	public $layout='//layouts/column1';

    /**
	 * @var array context menu items. This property will be assigned to {@link CMenu::items}.
	 */
	public $menu=array();

    /**
	 * @var array the breadcrumbs of the current page. The value of this property will
	 * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
	 * for more details on how to specify this property.
	 */
	public $breadcrumbs=array();

    private $leftMenu=array(
        'home'=>array(
            'url'=>'',
            'submenu'=>array(),
        ),
        'products'=>array(
            'url'=>'catalog/products',
            'submenu'=>array(),
        ),
        'articles'=>array(
            'url'=>'info/articles',
            'submenu'=>array(),
        ),
        'about'=>array(
            'url'=>'info/about',
            'submenu'=>array(),
        ),
    );

    public function init()
    {
        if(Yii::app()->request->getQuery('language')){
            $lang=Yii::app()->request->getQuery('language');
            Yii::import('application.models.local.Language');
            if(Language::model()->getLang($lang)){
                Yii::app()->language=$lang;
                Yii::app()->user->setState('language', $lang);
            }
            unset($_GET['language']);
            $this->redirect(Yii::app()->createUrl('',$_GET));
        }elseif(Yii::app()->user->hasState('language')){
            Yii::app()->language=Yii::app()->user->getState('language');
        }else{
            Yii::app()->language=Setting::getConfig('config_language');
            Yii::app()->user->setState('language', Yii::app()->language);
        }
        return parent::init();
    }

    public function getLeftMenu()
    {
        if(!Yii::app()->user->isGuest){
            $this->leftMenu['account']=array(
                'url'=>'account/index',
                'submenu'=>array(),
            );
            $this->leftMenu['logout']=array(
                'url'=>'account/index/logout',
                'submenu'=>array(),
            );
        }
        return $this->leftMenu;
    }

    public function getHeader()
    {
        $this->renderPartial('application.views.common.__header',array(
            'logo'=>Setting::model()->getConfig('config_main_logo_img'),
            'phone'=>Setting::model()->getConfig('config_telephone'),
        ));    }

    public function getFooter()
    {
        $this->renderPartial('application.views.common.__footer');
    }
}